<p>Assignments within sub-expressions are hard to spot and therefore make the code less readable. Ideally, sub-expressions should not have
side-effects.</p>
<h2>Noncompliant Code Example</h2>
<pre>
if ((str = cont.substring(pos1, pos2)).isEmpty()) {  // Noncompliant
  //...
</pre>
<h2>Compliant Solution</h2>
<pre>
str = cont.substring(pos1, pos2);
if (str.isEmpty()) {
  //...
</pre>
<h2>Exceptions</h2>
<p>Assignments in <code>while</code> statement conditions, and assignments enclosed in relational expressions are ignored.</p>
<pre>
BufferedReader br = new BufferedReader(/* ... */);
String line;
while ((line = br.readLine()) != null) {...}
</pre>
<p>Chained assignments, including compound assignments, are ignored.</p>
<pre>
int i = j = 0;
int k = (j += 1);
result = (bresult = new byte[len]);
</pre>
<h2>See</h2>
<ul>
  <li> <a href="https://cwe.mitre.org/data/definitions/481.html">MITRE, CWE-481</a> - Assigning instead of Comparing </li>
  <li> <a href="https://wiki.sei.cmu.edu/confluence/x/ZNYxBQ">CERT, EXP45-C.</a> - Do not perform assignments in selection statements </li>
  <li> <a href="https://wiki.sei.cmu.edu/confluence/x/ITZGBQ">CERT, EXP51-J.</a> - Do not perform assignments in conditional expressions </li>
</ul>

